<template>
  <div id="exchangeorder">  

    <el-form ref="form" :model="form" label-width="80px">  
     <el-row> 

        <el-col :span="18" style="display:flex;">

            <el-form-item label="" label-width="0px">
                <el-select  v-model="form.select_num" placeholder="请选择状态" style="width:160px;">
                    <el-option  v-for="(item,index) in select_data" :key="index" :label="item.name" :value="item.id"></el-option>
                </el-select>
            </el-form-item>

           <el-form-item label="" label-width="0px" style="margin-left:10px;" >
                 <el-date-picker type="date" :clearable='false' @change="data_change" placeholder="选择日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd"  v-model="form.time" style="width:160px;"></el-date-picker>
            </el-form-item>

            <el-form-item label-width="0px" style="margin-left:10px;">
               <el-input v-model="form.bh" :placeholder="variable_name4 + '编号'" style="width:160px;"></el-input>
            </el-form-item>

            <el-form-item label-width="0px" style="margin-left:10px;">
               <el-input v-model="form.phone" placeholder="账户" style="width:160px;"></el-input>
            </el-form-item>


           <div class="custom_button2"  style="margin-left:10px;" @click="search_but"></div>
        </el-col>

        <el-col :span="6" style="text-align: right;">  
            <el-button type="primary" v-if="export_type" class="custom_color_button" style="margin-bottom:10px;"  @click="output">是否导出</el-button> 
            <el-button type="primary" v-if="export_type1" class="custom_color_button" style="margin-bottom:10px;"  @click="output1">导出-{{ export_title }}</el-button>   
            <el-button type="primary" class="custom_color_button" style="margin-bottom:10px;" @click="refresh_but()">刷新</el-button>            
        </el-col>
    
    </el-row> 
   
   </el-form>
   <!-- 渲染数据list -->
   <exchangeorder-list1 :datalist="datalist" @up_list_fun="list_fun"> </exchangeorder-list1>

      
   <div style="margin-top:20px;text-align: center;">
      <el-pagination
        background
        @current-change="handleCurrentChange"
        :page-size="10"  
        layout="prev, pager, next, jumper"
        :total="count">
      </el-pagination>
    </div>


    <!-- 导出表格数据表格 -->
        <el-table v-show="false" :data="export_datalist" id="mytable1" style="width: 100%;height:10px;">
                 <el-table-column label="抢购时间"  align='center' width="180">                   
                    <template slot-scope="scope">                   
                        <span >{{ scope.row.time }}</span>
                    </template>
                </el-table-column>
                <el-table-column :label="variable_name4 + '等级'"  align='center' width="150">                   
                    <template slot-scope="scope">                   
                        <span >{{ scope.row.manor_title }}</span>
                    </template>
                </el-table-column>
                <el-table-column :label="variable_name4 + '价值'"  align='center' width="150">                   
                    <template slot-scope="scope">                   
                        <span >{{ scope.row.price }}</span>
                    </template>
                </el-table-column>
                <el-table-column :label="variable_name4 + '编号'"  align='center' width="230">                   
                    <template slot-scope="scope">                   
                        <span >{{ scope.row.pid }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="订单状态"  align='center'  width="150" >                   
                    <template slot-scope="scope">                   
                        <span v-if="scope.row.status == 'WAIT_SUBMIT_VOUCHER'">待上传凭证</span>
                        <span v-if="scope.row.status == 'SUBMITTED_VOUCHER'"> 已提交凭证</span>
                        <span v-if="scope.row.status == 'REJECT'"> 驳回</span>
                        <span v-if="scope.row.status == 'RESUBMITTED_VOUCHER'"> 重新提交凭证</span>
                        <span v-if="scope.row.status == 'APPEAL_SELLER'"> 出让方申述</span>
                        <span v-if="scope.row.status == 'APPEAL_BUYER'"> 兑换方申述</span>
                        <span v-if="scope.row.status == 'CONFIRMED'"> 已完成</span>
                        <span v-if="scope.row.status == 'NOT_SUMBIT_IN_TEN_MINUTES'"> 30分钟未上传</span>
                        <span v-if="scope.row.status == 'NOT_SUMBIT_IN_TEN_MI'"> 30分钟未上传</span>
                        <span v-if="scope.row.status == 'NOT_SUMBIT_FOR_SECOND'"> 未二次上传</span>
                        <span v-if="scope.row.status == 'SELLER_OVERTIME'"> 超时自动完成</span>
                        <span v-if="scope.row.status == 'CANCELLED_BUYER'"> 兑换方确认申诉</span>
                        <span v-if="scope.row.status == 'CANCELLED_SELLER'"> 出让方确认申诉</span>
                        <span v-if="scope.row.status == 'WAIT_ADMIN_EXAMINE'">申述待判定</span>
                        <span v-if="scope.row.status == 'ERROR_FOR_BUYER'">兑换方责任</span>
                        <span v-if="scope.row.status == 'ERROR_FOR_SELLER'">出让方责任</span>
                    </template>
                </el-table-column>
                <el-table-column label="出让方账号"  align='center'  width="150" >                   
                    <template slot-scope="scope">                   
                        <span >{{ scope.row.saler_telphone }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="出让方姓名"  align='center'  width="150" >                   
                    <template slot-scope="scope">                   
                        <span >{{ scope.row.saler_nickname }}</span>
                    </template>
                </el-table-column>
                 <el-table-column label="兑换方账号"  align='center'  width="150" >                   
                    <template slot-scope="scope">                   
                        <span >{{ scope.row.buyer_telphone }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="兑换方姓名"  align='center'  width="150" >                   
                    <template slot-scope="scope">                   
                        <span >{{ scope.row.buyer_nickname }}</span>
                    </template>
                </el-table-column>
        </el-table> 
    

      
  </div>
</template>

<script>

import FileSaver from 'file-saver'
import XLSX from 'xlsx'

import ExchangeorderList1 from '@/view/Exchangeorder/ExchangeorderList1'
export default {
  name: 'exchangeorder',
  data () {
    return {
        datalist:[],
        page:1,
        count:0,
        form:{
          time:'',
          phone:'',
          bh:'',
          select_num:''
        },
        select_data:[{"id":"cancel_no_submit","name":"未上传凭证取消"},{"id":"cancel_no_finished","name":"未完成订单取消"},{"id":"wait_submit","name":"未上传凭证"},
          {"id":"submitted_first","name":"待确认/上传凭证"},{"id":"reject","name":"已驳回"},{"id":"submitted_second","name":"新上传"},{"id":"seller_appeal","name":"出让方申述"},
          {"id":"buyer_appeal","name":"兑换方申述"},{"id":"finish","name":"已完成"},{"id":"overtime","name":"超时自动完成"},{"id":"wait_admin","name":"申述待判定"},
          {"id":"seller_reason","name":"出兑方责任"},{"id":"buyer_reason","name":"兑换方责任"},{"id":"seller_mistake","name":"出让方确认申述"}
          ,{"id":"buyer_mistake","name":"兑换方确认申述"}],
        export_type:false,
        export_type1:false,
        export_datalist:[],
        export_title:'不可导出'
    }
  },
 components:{
    ExchangeorderList1
  },
  created(){
    //  this.form.time = this.getNowDate1()
     this.list_fun()
  },
  mounted (){
    
  },
  methods: {
      list_fun(){
          this.post("/trade_goods/listOfData", {
              page:this.page,
              pid:this.form.bh,
              onetime:this.form.time,
              telphone:this.form.phone,
              type:this.form.select_num,
              search_all:0 //0 分页 1 全部
	        }).then(res => {
            this.count = res.result.count
            this.datalist = res.result.list

              for(let item of this.datalist) {

                // item.collection_pictureList = [this.urlimg + item.collection_picture]  //微信、支付宝
                item.voucher_linkList = [this.urlimg + item.voucher_link]  //上传凭证
                item.reason_pictureList = [this.urlimg + item.reason_picture]  //原因凭证

                //  for(let a of item.qr_code) {
                //    if(a.collection_type == 1){
                //       item.srcListwx = a.collection_picture
                //       item.srcList1 = [this.urlimg + a.collection_picture]
                //    }else if(a.collection_type == 2){
                //       item.srcListzfb = a.collection_picture
                //       item.srcList2 = [this.urlimg + a.collection_picture]
                //    }else if(a.collection_type == 3){
                //       item.srcListysf = a.collection_picture
                //       item.srcList3 = [this.urlimg + a.collection_picture]
                //    }else if(a.collection_type == 4){
                //       item.srcListjh = a.collection_picture
                //       item.srcList4 = [this.urlimg + a.collection_picture]
                //    }else if(a.collection_type == 5){
                //       item.srcListyhk = a.collection_picture
                //       item.srcList5 = [this.urlimg + a.collection_picture]
                //    }
                // }

              }

            console.log(res)
         })
      },
      export_fun(){
         this.post("/trade_goods/listOfData", {
              page:1,
              pid:'',
              onetime:this.form.time,
              telphone:this.form.phone,
              type:'',
              search_all:1 //0 分页 1 全部
	        }).then(res => {
             this.export_datalist = res.result.list
             this.export_title = "可导出"
             this.export_type = false
             this.export_type1 = true
             //console.log(res)
         })
      },
      search_but(){
        if(this.form.phone != ''  || this.form.time != ''){ //是否出现导出按钮
              
             this.export_type = true
             this.export_type1 = false
             this.export_datalist = []
             this.export_title = "不可导出"
            
        }else{
             this.export_type = false
             this.export_type1 = false
             this.export_datalist = []
             this.export_title = "不可导出"
        }
        this.page = 1
        this.list_fun()
      },
      output() {
         this.export_fun()     
      },
      output1(){
          if( this.form.phone != ''  || this.form.time != ''){ //是否出现导出按钮
               
              var wb = XLSX.utils.table_to_book(document.querySelector("#mytable1"));//mytable为表格的id名
              var wbout = XLSX.write(wb, {
                bookType: "xlsx",
                bookSST: true,
                type: "array"
              });
              try {
                FileSaver.saveAs(
                  new Blob([wbout], { type: "application/octet-stream" }),
                  "sheet.xlsx"
                );
              } catch (e) {
                if (typeof console !== "undefined") console.log(e, wbout);
              }
              return wbout;   

        }else{
            this.export_datalist = []
             this.export_title = "不可导出"
            this.open1('只能导出搜索手机号与日期的数据','success')  //提示框
           
        }
      },
      refresh_but(){
        this.page = 1
        this.form={
          time:'',
          phone:'',
          bh:'',
          select_num:''
        }
        this.export_type = false
        this.list_fun()
        this.export_datalist = []
        this.export_title = "不可导出"
      },
       data_change(){
        console.log(this.form.time)
      },
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        this.page = val
        this.list_fun()
        console.log(`当前页: ${val}`);
      }
  }
}
</script>


<style scoped>
</style>
